import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/index/Index'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/login'
  },
  {
    path: '/console',
    name: 'Console',
    component: ()=> import(/* webpackChunkName: "console" */ '../views/console/Console.vue'),
    redirect: '/console/index',
    children:[
      {
        path: "index",
        name: "console",
        component: () => import("../views/index/Index"),
        meta:{
          title:"欢迎使用"
        }
      },
      {
        path: "dashboard_chart",
        name: "dashboard_chart",
        component: () => import("../views/daChart/DaChart"),
        meta: {
          title: "图表风格",
      },
      },
      {
        path: "dashboard_home",
        name: "dashboard_home",
        component: () => import("../views/daHome/Dahome"),
        meta: {
          title: "主页",
      },
      },
      {
        path: "role_management",
        name: "role_management",
        component: () => import("../views/role_management/Role_management"),
        meta: {
          title: "角色管理",
      },
      },
      {
        path: "perm_management",
        name: "perm_management",
        component: () => import("../views/perm_management/Perm_management"),
        meta: {
          title: "权限管理",
      },
      },
      {
        path: "admin_management",
        name: "admin_management",
        component: () => import("../views/admin_management/Admin_management"),
        meta: {
          title: "账号管理",
      },
      },
      // 404 页面跳转
  {
    path: '*',
    name: 'error',
    component: ()=>import('../views/error/error.vue'),
    meta: {
      title: "错误页面",
  },
  },
    ]
  },
  {
    path: '/login',
    name: 'Login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "Login" */ '../views/login/Login.vue')
  }
]


/**
 * 添加动态路由
 * ! 常量路由: 所有用户登录均可展示
 */
// export const constantRoutes = [
//   {
//     path: '/',
//     name: 'Login',
//     // route level code-splitting
//     // this generates a separate chunk (about.[hash].js) for this route
//     // which is lazy-loaded when the route is visited.
//     component: () => import( /* webpackChunkName: "Login" */ '../views/login/Login.vue')
//   },
//   {
//   path: '/login',
//   name: 'Login',
//   // route level code-splitting
//   // this generates a separate chunk (about.[hash].js) for this route
//   // which is lazy-loaded when the route is visited.
//   component: () => import( /* webpackChunkName: "Login" */ '../views/login/Login.vue')
// },
//       // 404 页面跳转
//       {
//         path: '*',
//         name: 'error',
//         component: () => import('../views/error/error.vue'),
//         meta: {
//           title: "错误页面",
//         },
//       },
// ]

/**
 * 添加动态路由
 */

// export const asyncRuters = [{
//     path: '/console',
//     name: 'Console',
//     component: () => import( /* webpackChunkName: "console" */ '../views/console/Console.vue'),
//     redirect: '/console/index',
//     children: [{
//         path: "index",
//         name: "console",
//         component: () => import("../views/index/Index"),
//         meta: {
//           title: "欢迎使用"
//         }
//       },
//       {
//         path: "dashboard_chart",
//         name: "dashboard_chart",
//         component: () => import("../views/daChart/DaChart"),
//         meta: {
//           title: "图表风格",
//         },
//       },
//       {
//         path: "dashboard_home",
//         name: "dashboard_home",
//         component: () => import("../views/daHome/Dahome"),
//         meta: {
//           title: "主页",
//         },
//       },
//       {
//         path: "role_management",
//         name: "role_management",
//         component: () => import("../views/role_management/Role_management"),
//         meta: {
//           title: "角色管理",
//         },
//       },
//       {
//         path: "perm_management",
//         name: "perm_management",
//         component: () => import("../views/perm_management/Perm_management"),
//         meta: {
//           title: "权限管理",
//         },
//       },
//       {
//         path: "admin_management",
//         name: "admin_management",
//         component: () => import("../views/admin_management/Admin_management"),
//         meta: {
//           title: "账号管理",
//         },
//       }
//     ]
//   }
// ]









const router = new VueRouter({
  // routes:constantRoutes
  routes
})

// 添加路由拦截
/* router.beforeEach((from,to,next)=>{
  if(to.fullPath==='/login'){
    next();
  } else {
    const token = localStorage.getItem('token')
    if(token===null||token===''){
      next('/login')
    }
  }
}) */
export default router